<template>
    <!--flex弹性盒子模型，justify-content：主抽 -->
    <div style="display: flex; justify-content: center;">
        <el-form style="font-weight: bold;color: #409EFF;" :model="ruleForm" status-icon :rules="rules" ref="ruleForm" :disabled="formDisabled" label-width="80px" class="demo-ruleForm">
            <el-row>
                <el-col :span="10">
                    <el-form-item label="登录名" prop="userId">
                        <el-input type="text" v-model="ruleForm.userId" :disabled="true" placeholder="请输入登录名" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10">
                    <el-form-item label="昵称" prop="userName">
                        <el-input type="text" v-model="ruleForm.userName" placeholder="请输入昵称" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" >
                    <el-form-item label="手机号" prop="mobilePhone">
                        <el-input type="text" placeholder="请输入手机号码" maxlength="11" v-model="ruleForm.mobilePhone" autocomplete="off" show-word-limit></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10">
                    <el-form-item label="性别" prop="sex">
                        <el-select v-model="ruleForm.sex" filterable clearable size="medium" placeholder="请选择性别">
                            <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="10">
                    <el-form-item label="年龄" prop="age">
                        <el-input type="text" v-model="ruleForm.age" placeholder="请输入年龄" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10">
                    <el-form-item label="生日" prop="birthDay">
                        <el-date-picker v-model="ruleForm.birthDay" type="date" placeholder="请选择出生日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="10" >
                    <el-form-item label="住址" prop="address">
                        <el-input type="text" v-model="ruleForm.address" placeholder="请输入住址" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col v-if="!formDisabled" :span="24">
                    <el-button style="margin-top: 20px;" type="primary" class="sub" @click="updateUserMsg">保存</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>

import Vue from 'vue'
import { Button, Form, FormItem, Input, Message } from 'element-ui'
import { updateUserMsg } from '../../api/index'

Vue.use(Button)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.prototype.$message = Message
export default {
  name: 'UserInfoDetail',
  data: function () {
    return {
      options: [
        {
          value: '1',
          label: '男'
        }, {
          value: '2',
          label: '女'
        }
      ],
      rules: {}
    }
  },
  methods: {
    updateUserMsg: function () {
      var that = this
      var params = {}
      params.userId = that.ruleForm.userId
      params.userName = that.ruleForm.userName
      params.mobilePhone = that.ruleForm.mobilePhone
      params.sex = that.ruleForm.sex
      params.age = that.ruleForm.age
      params.birthDay = that.ruleForm.birthDay
      params.address = that.ruleForm.address
      updateUserMsg(params)
        .then(res => {
          if (res.code === '000000') {
            that.$message({
              message: '修改用户信息成功',
              type: 'success'
            })
          } else {
            that.$message({
              message: res.message,
              type: 'warning'
            })
          }
        })
        .catch(failResponse => {})
    }
  },
  mounted: function () {
    this.showMask = this.value
  },
  props: {
    formDisabled: {
      type: Boolean,
      require: true
    },
    ruleForm: {
      type: Object,
      require: true
    }
  },
  watch: {
    value (newVal, oldVal) {
      this.showMask = newVal
    },
    showMask (val) {
      this.$emit('input', val)
    },
    closeMask () {
      this.showMask = false
    }
  }
}
</script>

<style scoped>
.login-title{
  margin-left: 20%;
  font-weight: bold;
  color: #409EFF;
}
.el-button--primary.sub{
  width: 50%;
}
.el-left{
  margin-left: -31%;
}
</style>
